package ipark.sistemski;

//TO JE KLASS KI BO ZNAL BRATI IZ FAJLA IN VPISOVAL V BAZO!!

import java.io.*;
import java.sql.*;
import java.util.logging.*;

public class BazaStatko {
        
      public void fileToDB(){
       BufferedReader br; 
       String tmp;
        PreparedStatement ps; 
       String sql = "INSERT STATISTICS (noenter,noexit,nobuyouts,noerrors,nofixed,earnings) VALUES (?,?,?,?,?,?)";
       
        try {
            ps = DBConnect.connection().prepareStatement(sql);
            
            br = new BufferedReader(new FileReader("STF.txt"));
            int i=1;
            for(int j=1; j<=7; j++){
                tmp=br.readLine();
                if(j==2 || j==4 || j==5 || j==6 || j==7 ){
                int intedzer = Integer.parseInt(tmp);
                ps.setInt(i, intedzer);
                i++;
                }
            }
            tmp=br.readLine();
            tmp=br.readLine();
            double dobl = Double.parseDouble(tmp);
            ps.setDouble(6, dobl);
            ps.execute();
            br.close();
            System.out.println("<<< Podatki spremenljivk statistike so, bili ob 0:00 uri uspesno shranjeni v bazo. >>>");
    
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Statko.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
                Logger.getLogger(Statko.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
            Logger.getLogger(BazaStatko.class.getName()).log(Level.SEVERE, null, ex);
            }
       }
}